package com.gwtjs.hbm2web.extjs.util;

import java.util.Properties;

public class DataTypeJavaToExt {
	private static DataTypeJavaToExt type = new DataTypeJavaToExt();
	private Properties pro = null;
	
	private DataTypeJavaToExt() {
		this.pro= new Properties();
		this.pro.setProperty("0", "string");
		this.pro.setProperty("1", "int");
		this.pro.setProperty("2", "float");
		this.pro.setProperty("3", "date");
		this.pro.setProperty("4", "boolean");
		this.pro.setProperty("5", "auto");
	}
	
	private int getPropertiesIndex(String javaType){
		if("int".equals(javaType))
			return 1;
		if("shot".equals(javaType))
			return 1;
		if("Integer".equals(javaType))
			return 1;
		if("java.lang.Integer".equals(javaType))
			return 1;
		else if("long".equals(javaType))
			return 2;
		else if("java.lang.Long".equals(javaType))
			return 2;
		else if("double".equals(javaType))
			return 2;
		else if("java.lang.Double".equals(javaType))
			return 2;
		else if("float".equals(javaType))
			return 2;
		else if("java.util.Date".equals(javaType))
			return 3;
		else if("java.sql.Date".equals(javaType))
			return 3;
		else if("boolean".equals(javaType))
			return 4;
		else if("java.lang.Boolean".equals(javaType))
			return 4;
		else if("java.sql.Blob".equals(javaType))
			return 5;
		 
		return 0;
	}
	
	public static DataTypeJavaToExt getInstance(){
		return type;
	}
	
	public String getExtDataType(String javaType){
		String index = getPropertiesIndex(javaType)+"";
		return this.pro.getProperty(index);
	}
}
